<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="ie=edge" />
        <title>Document</title>
        <script src="../vue.js"></script>
        <style>
            .msg {
                width: 100px;
                height: 100px;
                border: 1px solid #000;
            }
        </style>
    </head>
    <body>
        <div id="app">
            <div class="msg" v-color-swatch="'gold'" v-abc:[msg]="isIf" v-show="isIf">{{msg}}</div>
        </div>
        <template>
            <div>
                <button></button>
            </div>
        </template>
        <script>
            Vue.directive('color-swatch', function (el, binding) {
                el.style.backgroundColor = binding.value;
            });
            let vm = new Vue({
                el: '#app',
                data() {
                    return {
                        msg: 'Hello',
                        isIf: 100,
                    };
                },
                methods: {},
                directives: {
                    abc: {
                        bind(el, binding, vNode) {
                            // console.log(el.parentNode); // Null
                            console.log('bind');
                        },
                        inserted(el, binding, vNode) {
                            // console.log(el.parentNode); // 可以拿到父节点
                            console.log('inserted');
                            console.log(this); // window
                            console.log(binding);
                            el.onmouseover = function () {
                                console.log(this); // window
                                this.style.width = '200px';
                                this.style.height = '200px';
                            };
                            el.onmouseout = function () {
                                this.style.width = this.style.height = '100px';
                            };
                        },
                        update(el, binding, vNode) {
                            console.log('update');
                        },
                        componentUpdated(el, binding, vNode) {
                            console.log('componentUpdated');
                        },
                        // 只会在DOM销毁的时候触发
                        unbind(el, binding, vNode) {
                            console.log('unbind');
                        },
                    },
                },
            });
        </script>
    </body>
</html>
